<?php 
function ajax_load_fc_btn_contact_form_send_ajax()
{ 	
	global $myoptions;
	
	$name 		= strip_tags($_REQUEST['mname']);
	$email 		= strip_tags($_REQUEST['memail']);
	$phone 		= strip_tags($_REQUEST['mphone']);
	$content 	= strip_tags($_REQUEST['mcontent']);
	$code 		= strip_tags($_REQUEST['mcode']);
	
	if($code!=$_SESSION['ma_xac_nhan'])
	{
		print_r(json_encode(__("Lỗi, mã an toàn sai.",THEMENAME)));
	}	
	else
	{	
		$to =  $myoptions['contact-email']?$myoptions['contact-email']:get_option('admin_email');
		$subject = 'Liên hệ từ khách hàng - '.get_bloginfo('name');
		
		$headers = "From: " . get_option('mail_from_name') . "\r\n";
		$headers .= "Reply-To: ". get_option('mail_from') . "\r\n";
		
		$headers .= "MIME-Version: 1.0\r\n";
		$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
		
		$message = '<html><body>';
		
		$message .= '<h1 style="font-size:15px;">Thông tin khách hàng</h1>';
		$message .= '<div><strong>Tên khách hàng:</strong> '.$name.'</div>';
		$message .= '<div><strong>Email:</strong> '.$email.'</div>';
		$message .= '<div><strong>Phone:</strong> '.$phone.'</div>';
		$message .= '<div><strong>Nội dung:</strong></div>';
		$message .= '<div>'.$content.'</div>';
		
		$message .= '</body></html>';
		
		wp_mail($to, $subject, $message,$headers);
		print_r(json_encode(__("Send email Successfull.",THEMENAME)));
	}	
	die(); // stop executing script
}

add_action( 'wp_ajax_btn-contact-form-send-ajax', 'ajax_load_fc_btn_contact_form_send_ajax' ); // ajax for logged in users
add_action( 'wp_ajax_nopriv_btn-contact-form-send-ajax', 'ajax_load_fc_btn_contact_form_send_ajax' ); // ajax for not logged in users

?>